function sum() {
  const result = {};
  return (...args) => {
    const arr = args.sort((a, b) => a - b);
    if(result[arr] !== undefined) {
      console.log('缓存')
      return result[arr]
    }
    console.log('计算')
    const s = args.reduce((p, n) => p + n, 0);
    result[arr] = s
    return s
  };
}

const compute = sum();

const s = compute(1,2,3)
const s1 = compute(2,1,3)
console.log(s, s1,)
